<template>
  <view class="normal-cell main-pd">
    <view class="msg-cell">
      <u-cell-group :border="false">
        <u-cell title="活动名称" :value="hdxx.title"></u-cell>
        <u-cell title="报名时间" v-if="hdxx.isSignup ==1">
          <template #label>
            <view class="u-m-t-10">{{
              hdxx.bmStartTime + "至" + hdxx.bmEndTime
            }}</view>
          </template>
        </u-cell>
        <u-cell title="活动时间">
          <template #label>
            <view class="u-m-t-10">{{
              hdxx.hdStartTime + "至" + hdxx.hdEndTime
            }}</view>
          </template>
        </u-cell>
        <u-cell title="活动地点">
          <template #label>
            <view class="u-m-t-10">{{ hdxx.address || "" }}</view>
          </template>
        </u-cell>
        <u-cell title="活动范围">
          <template #label>
            <view class="u-m-t-10">{{ hdxx.deptNames.join(",") || "" }}</view>
          </template>
        </u-cell>
        <u-cell title="活动简介" :border="false">
          <template #label>
            <view class="u-m-t-10">
              <u-parse :content="hdxx.content"></u-parse>
            </view>
          </template>
        </u-cell>
      </u-cell-group>
      <view class="column-item" v-show="JSON.parse(hdxx.files).length">
      <view class="label">附件：</view>
      <view
        class="file-item"
        v-for="item in JSON.parse(hdxx.files)"
        @click="downloadFile(item.fileurl)"
        :key="item.fileurl"
        >{{ item.filename }}</view
      >
    </view>
    </view>
    <view class="u-m-t-106 u-p-b-80" v-if="hdxx.isSignup==1&&!onlyDetail">
      <u-button
        text="我要报名"
        shape="circle"
        color="linear-gradient(90deg, #FA827D 0%, #F34B47 100%)"
        :customStyle="{
          fontSize: '36rpx',
          height: '96rpx',
        }"
        @click="$u.route('/pages/hdcy/join',{hdTime: hdxx.bmStartTime +'-'+hdxx.bmEndTime,activityId:activityId})"></u-button>
    </view>
  </view>
</template>

<script setup>
import { ref } from "vue";
import { getactiveInfoApi } from "@/api/index";
import { onLoad,onShow } from "@dcloudio/uni-app";
import useInfoStore from "@/store/user"
import config from "@/config";
const userStore = useInfoStore()
let onlyDetail = ref(false)
let hdxx = ref({});
const gethhbInfoHandle = (id) => {
  getactiveInfoApi({ id }).then((res) => {
    if (res.success) {
      hdxx.value = res.data;
    }
  });
};
let activityId = ref('')


  const downloadFile = (url) => {
  uni.downloadFile({
    url: config.baseUrl + url, //下载地址，后端接口获取的链接
    success: (data) => {
      if (data.statusCode === 200) {
        uni.saveFile({
          //文件保存到本地
          tempFilePath: data.tempFilePath, //临时路径
          success: function (res) {
            uni.showToast({
              icon: "none",
              mask: true,
              title: "点击右上角保存到手机",
              duration: 3000,
            });
            uni.openDocument({
              //fileType: 'docx',
              showMenu: true, //关键点,可以转发到微信
              filePath: res.savedFilePath,
              success: function (res) {},
            });
          },
        });
      }
    },
    fail: (err) => {
      uni.showToast({
        icon: "none",
        mask: true,
        title: "失败请重新下载",
      });
    },
  });
};
onLoad((param) => {
    activityId.value = param.id;
    onlyDetail.value = param.onlyDetail || false;
  gethhbInfoHandle(param.id);
});
onShow(()=>{
  uni.$on('refresh',(data)=>{
    if(data.refresh){
      gethhbInfoHandle(activityId.value)
    }
  })
})
</script>

<style lang="scss" scoped>
.column-item {
    .label {
      color: #1e1e1e;
      font-size: 26rpx;
      font-weight: bold;
      margin: 20rpx 0;
    }
    .file-item {
      margin: 20rpx 0;
      color: blue;
      font-size: 26rpx;
    }
  }
.hbxx-detail {
}
</style>
